from django.template import Library
from django.urls import reverse
from web import models

register = Library()


# 使用了装饰符
@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    my_creator = models.Project.objects.filter(creator=request.tracer.user)
    join_project = models.ProjectUser.objects.filter(user=request.tracer.user)
    return {"my_creator": my_creator, "join_project": join_project, "request": request}


# 给项目页面创建菜单
@register.inclusion_tag('inclusion/manage_list.html')
def manage_menu_list(request):
    data_list = [
        {'title': "项目简介", 'url': reverse("websass:dashboard", kwargs={'project_id': request.tracer.project.id})},
        {'title': "wiki", 'url': reverse("websass:wiki", kwargs={'project_id': request.tracer.project.id})},
        {'title': "统计", 'url': reverse("websass:statistics", kwargs={'project_id': request.tracer.project.id})},
        {'title': "配置", 'url': reverse("websass:settings", kwargs={'project_id': request.tracer.project.id})},
        {'title': "文件", 'url': reverse("websass:file", kwargs={'project_id': request.tracer.project.id})},
        {'title': "问题", 'url': reverse("websass:issues", kwargs={'project_id': request.tracer.project.id})},
        {'title': "数据爬取", 'url': reverse("websass:data_crawl", kwargs={'project_id': request.tracer.project.id})},

    ]
    for item in data_list:
        if request.path_info.startswith(item['url']):
            item['class'] = 'active'
    return {'data_list': data_list}
